import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:go_router/go_router.dart';

class ProfileScreen extends StatelessWidget {
  const ProfileScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Column(
          children: [
            _buildUserCard(),
            const SizedBox(height: 8),
            // 服务菜单
            _buildMenuItem(
              icon: Icon(
                Icons.chat_bubble_outline,
                color: const Color(0xFF07C160),
                size: 24.r,
              ),
              title: '服务',
              context: context,
            ),
            // 收藏
            _buildMenuItem(
              icon: Icon(
                Icons.inbox_outlined,
                color: const Color(0xFFFF9C19),
                size: 24.r,
              ),
              title: '收藏',
              context: context,
            ),
            // 朋友圈
            _buildMenuItem(
              icon: Icon(
                Icons.photo_library_outlined,
                color: const Color(0xFF2BA245),
                size: 24.r,
              ),
              title: '朋友圈',
              context: context,
            ),
            // 视频号
            _buildMenuItem(
              icon: Icon(
                Icons.play_circle_outline,
                color: const Color(0xFFFF9C19),
                size: 24.r,
              ),
              title: '视频号',
              context: context,
            ),
            // 卡包
            _buildMenuItem(
              icon: Icon(
                Icons.credit_card,
                color: const Color(0xFF1485EE),
                size: 24.r,
              ),
              title: '卡包',
              context: context,
            ),
            // 表情
            _buildMenuItem(
              icon: Icon(
                Icons.emoji_emotions_outlined,
                color: const Color(0xFFFFBE00),
                size: 24.r,
              ),
              title: '表情',
              context: context,
            ),
            Container(
              height: 8.h,
              color: const Color(0xFFF7F7F7),
            ),
            // 设置
            _buildMenuItem(
              icon: Icon(
                Icons.settings_outlined,
                color: const Color(0xFF8E8E93),
                size: 24.r,
              ),
              title: '设置',
              context: context,
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildUserCard() {
    return Container(
      padding: EdgeInsets.only(
        left: 16.w,
        right: 16.w,
        top: 48.h,
        bottom: 8.h,
      ),
      child: Row(
        children: [
          // 头像
          CircleAvatar(
            radius: 30.r,
            backgroundImage:
                const NetworkImage('https://placekitten.com/200/200'),
          ),
          SizedBox(width: 12.w),
          // 用户信息
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '九月',
                  style: TextStyle(
                    fontSize: 20.sp,
                    fontWeight: FontWeight.w500,
                  ),
                ),
                SizedBox(height: 4.h),
                Text(
                  '微信号：lipeng3211',
                  style: TextStyle(
                    fontSize: 14.sp,
                    color: Colors.grey[600],
                  ),
                ),
                SizedBox(height: 8.h),
                Row(
                  children: [
                    _buildTag('状态', Icons.add),
                    SizedBox(width: 8.w),
                    _buildTag('2个朋友', Icons.person_outline, showDot: true),
                  ],
                ),
              ],
            ),
          ),
          // 二维码和箭头
          Icon(Icons.qr_code_2, size: 20.r, color: Colors.grey[600]),
          SizedBox(width: 4.w),
          Icon(Icons.chevron_right, size: 20.r, color: Colors.grey[400]),
        ],
      ),
    );
  }

  Widget _buildTag(String text, IconData icon, {bool showDot = false}) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 4.h),
      decoration: BoxDecoration(
        color: const Color(0xFFF7F7F7),
        borderRadius: BorderRadius.circular(16.r),
      ),
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          Icon(icon, size: 16.r, color: Colors.grey[600]),
          SizedBox(width: 4.w),
          Text(
            text,
            style: TextStyle(
              fontSize: 13.sp,
              color: Colors.grey[600],
            ),
          ),
          if (showDot) ...[
            SizedBox(width: 4.w),
            Container(
              width: 6.r,
              height: 6.r,
              decoration: const BoxDecoration(
                color: Colors.red,
                shape: BoxShape.circle,
              ),
            ),
          ],
        ],
      ),
    );
  }

  Widget _buildMenuItem({
    required Icon icon,
    required String title,
    required BuildContext context,
  }) {
    return Column(
      children: [
        ListTile(
          leading: icon,
          title: Text(
            title,
            style: TextStyle(
              fontSize: 16.sp,
              fontWeight: FontWeight.w400,
            ),
          ),
          trailing:
              Icon(Icons.chevron_right, size: 20.r, color: Colors.grey[400]),
          contentPadding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 2.h),
          onTap: () {
            if (title == '服务') {
              context.push('/wallet');
            }
          },
        ),
        Divider(height: 1.h, indent: 56.w),
      ],
    );
  }
}
